package com.example.helloworld;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.LinearLayout;

import com.google.ads.*;

public class AdViewActivity extends Activity {
    private AdView adView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ad_view);
     
        // Create the adView using our Admob Publisher ID
        adView = new AdView(this, AdSize.BANNER, "a151644e6de0b6d");

        // Lookup your LinearLayout using the R.id.***** naming
        LinearLayout layout = (LinearLayout)findViewById(R.id.adLayout);

        // Add the adView to it
        layout.addView(adView);
        AdRequest request = new AdRequest();
        // Initiate a generic request to load it with an ad
        adView.loadAd(request);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.ad_view, menu);
        return true;
    }

    /*
     * A required method to destroy the ad when necessary
     * @see android.app.Activity#onDestroy()
     */
    @Override
    public void onDestroy() {
      if (adView != null) {
        adView.destroy();
      }
      super.onDestroy();
    }
}
